<?php

class Zend_Controller_ActionAquiles extends Zend_Controller_Action {

    public function init() {
        $sessionErros = new Zend_Session_Namespace('erros');
        if(isset($sessionErros->erros) && !empty($sessionErros->erros)){
            $this->view->erros = $sessionErros->erros;
        }
        $sessionErros->unsetAll();
        
        $sessionMsg = new Zend_Session_Namespace('msg');
        if(isset($sessionMsg->msgs) && !empty($sessionMsg->msgs)){
            $this->view->msg = $sessionMsg->msgs;
        }
        $sessionMsg->unsetAll();
        
        
        $this->view->title = 'Júlia e Bassu, setem o $this->view->title no init do controller';
        parent::init();
    }
    
    protected function replaceMoneyEua($arrayDate, $arrayName) {
        if (is_array($arrayDate) && count($arrayDate) > 0) {
            if (is_array($arrayName) && count($arrayName) > 0) {

                foreach ($arrayName as $index) {
                    if (array_key_exists($index, $arrayDate) && isset($arrayDate[$index]) && !empty($arrayDate[$index])) {
                        $arrayDate[$index] = str_replace(',', '.', $arrayDate[$index]);
                        $arrayDate[$index] = number_format($arrayDate[$index], 2, ".", ",");
                    } else {
                        $arrayDate[$index] = null;
                    }
                }
            }
        }

        return $arrayDate;
    }

    protected function populaXml($dados, $labelsData, $labelsVlr) {

        $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
        $xml.= "<root>";
        $xml.="<rows>";
        $xml.="<page>" . $dados->getCurrentPageNumber() . "</page>";
        $xml.="<total>" . $dados->getTotalItemCount() . "</total>";
        foreach ($dados as $keyDados => $linha) {
            $xml.="<row id='" . $keyDados . "'>";
            foreach ($linha as $keyLinha => $valueLinha) {
                $achou = false;
                if( isset($labelsData)){
                    foreach ($labelsData as $data) {
                        if ($data == $keyLinha) {
                            $xml.="<cell><![CDATA[" . Util_Function_Util::formataData($valueLinha) . "]]></cell>";
                            $achou = true;
                        }
                    }
                }

                if (!$achou && isset($labelsVlr)) {
                    foreach ($labelsVlr as $data) {
                        if ($data == $keyLinha) {
                            $xml.="<cell><![CDATA[" . Util_Function_Util::formataMoeda($valueLinha) . "]]></cell>";
                            $achou = true;
                        }
                    }
                }
                if (!$achou) {
                    $xml.="<cell><![CDATA[" . $valueLinha . "]]></cell>";
                }
                
            }
            $xml.="</row>";
        }
        $xml.="</rows>";
        $xml.="</root>";
        return $xml;
    }
}

?>